package com.org.litepal.slice.aggregate;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import org.litepal.harmony.ResourceTable;

/**
 * 聚合函数
 */
public class AggregateAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_aggregate);

        Button btnCount = (Button) findComponentById(ResourceTable.Id_count_sample_btn);
        Button btnMax = (Button) findComponentById(ResourceTable.Id_max_sample_btn);
        Button btnMin = (Button) findComponentById(ResourceTable.Id_min_sample_btn);
        Button btnAverage = (Button) findComponentById(ResourceTable.Id_average_sample_btn);
        Button btnSum = (Button) findComponentById(ResourceTable.Id_sum_sample_btn);

        //统计
        btnCount.setClickedListener(component -> present(new CountSampleAbilitySlice(), new Intent()));
        //最大值
        btnMax.setClickedListener(component -> present(new MaxSampleAbilitySlice(), new Intent()));
        //最小值
        btnMin.setClickedListener(component -> present(new MinSampleAbilitySlice(), new Intent()));
        //平均数
        btnAverage.setClickedListener(component -> present(new AverageSampleAbilitySlice(), new Intent()));
        //求和
        btnSum.setClickedListener(component -> present(new SumSampleAbilitySlice(), new Intent()));
    }
}